﻿using Pay.DTO;
using Pay.IService;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Security;
using Pay.TO;

namespace Pay.Web.Areas.Admin.Controllers
{
    [RouteArea("admin")]
    [RoutePrefix("course")]
    public class CourseController : AdminController {
        private ICourseService _iCourseService;

        public CourseController(ICourseService iCourseService) {
            _iCourseService = iCourseService;
        }
        [HttpGet]
        public JsonResult Gets(CourseQuery query) {
            var result = _iCourseService.Gets(query);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public JsonResult Get(long id) {
            var result = _iCourseService.Get(id);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public JsonResult Enable(long id, bool isEnable) {
            var result = _iCourseService.Enable(id, isEnable);
            return Json(ResultToJson.Json(result ? " 保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
        }
        [HttpDelete]
        public JsonResult Delete(int id) {
            var result = _iCourseService.Delete(id);
            return Json(ResultToJson.Json(result ? " 删除成功" : "删除失败", result), JsonRequestBehavior.AllowGet);
        }
     [HttpPost]
        public JsonResult Save(course_dto model) {
            var result = _iCourseService.Save(model);
            return Json(ResultToJson.Json(result ? "保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
        }
    }
}